package cn.gaily.oss.controller;

import cn.gaily.commonutils.R;
import cn.gaily.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

@Slf4j
@Api(description = "oss上传接口")
@RestController
@RequestMapping("/eduoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping("/fileoss")
    //用MultipartFile得到上传文件
    public R uploadOssFile(@ApiParam(name = "file", value = "文件", required = true)
                               @RequestParam("file") MultipartFile file){
        String url = ossService.uploadFileAvatar(file);
        log.info(url);
        return R.ok().data("url",url);
    }
}
